package com.situ.controller;

import com.situ.entity.BeOrder;
import com.situ.entity.BeOrderUser_Lw;
import com.situ.service.BeOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import com.situ.service.BeOrderuserService;
import com.situ.entity.BeOrderuser;
import com.situ.entity.BeOrderUser_Lw;

import java.beans.PropertyEditor;
import java.text.DateFormat;
import java.text.SimpleDateFormat;

import java.util.*;

/**
 * BeOrderuser的路由接口服务
 * 
 * @author 胡文
 *
 */
@Controller
public class BeOrderuserController {

	/** BeOrderuserService服务 */
	@Autowired
	private BeOrderuserService beOrderuserService;
	@Autowired
	private BeOrderService beOrderService;
	
	/**
	 * 查询所有BeOrderuser数据的方法
	 * @param value
	 * @return
	 */
	@RequestMapping(value = "queryBeOrderuser", produces = {"application/json;charset=UTF-8"})
	public String find(BeOrderuser value,Map map) {
		 List<BeOrderuser> list= beOrderuserService.find(value);
         map.put("items",list);
         return "页面名称自己改";
	}
	@InitBinder  //时间类型装换器
	public void dateconvert(WebDataBinder bind){
		DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		PropertyEditor n=new CustomDateEditor(format, true);
		bind.registerCustomEditor(Date.class, n);
	}
	//施工竣工保存不发送
	//批量修改施工竣工的客户信息
	@RequestMapping("updateSgjg")
	public String updateSgjg(BeOrder ore,BeOrderUser_Lw orduse){
		beOrderService.updateShi(ore, orduse);
		return "redirect:/be__working.html";
	}
	//施工竣工保存发送
	@RequestMapping("updateSgjg2")
	public String updateSgjg2(BeOrder ore,BeOrderUser_Lw orduse){

		ore.setStepID(7);
		beOrderService.updateShi(ore, orduse);
		return "redirect:/be__open.html";
	}
	//档案存档：保存发送
	@RequestMapping("updateKh")
		public String updateKh(BeOrder ore,BeOrderUser_Lw orduse){

			ore.setStepID(0);
			beOrderService.updateNotNullById(ore);
			for (BeOrderuser b :orduse.getList() ){

				beOrderuserService.updateNotNullById(b);
			}
			return "redirect:/queryAllOrd.html";
		}

	//雷雯：保存不发送！批量修改档案存档编号

	@RequestMapping("addKh2")
	public String addKh(BeOrderUser_Lw orduse){
		//ore.setStepID(0);
		//beOrderService.updateNotNullById(ore);
		for (BeOrderuser b :orduse.getList() ){
			
			beOrderuserService.updateNotNullById(b);
		}
		return "redirect:/be__save.html";
	}
	
	/**
	 * 通过id查询BeOrderuser数据的方法
	 * 
	 * @return
	 */
	@RequestMapping(value = "queryBeOrderuserById/{id}", produces = {"application/json;charset=UTF-8"})
	public String findOne(@PathVariable(name="id") Object id,Map map) {
        BeOrderuser obj=  beOrderuserService.findOne(id);
        map.put("BeOrderuser",obj);
        return "页面名称自己改";
	}
	
	/**
	 * 插入BeOrderuser属性不为空的数据方法
	 * 
	 * @return
	 */
	@RequestMapping(value = "saveBeOrderuser", produces = {"application/json;charset=UTF-8"})
	public String save(BeOrderuser value) {
		  beOrderuserService.saveNotNull(value);
        return "redirect:/queryBeOrderuser";
	}
	
	/**
	 * 更新BeOrderuser属性不为空的数据方法
	 * 
	 * @return
	 */
	@RequestMapping(value = "updateBeOrderuser", produces = {"application/json;charset=UTF-8"})
	public String update(BeOrderuser value) {
		  beOrderuserService.updateNotNullById(value);
          return "redirect:/queryBeOrderuser";
	}
	
	/**
	 * 通过id删除BeOrderuser数据方法
	 * 
	 * @return
	 */
	@RequestMapping(value = "delBeOrderuserById/{id}", produces = {"application/json;charset=UTF-8"})
	public String delete(@PathVariable(name="id") Object id) {
		  beOrderuserService.deleteById(id);
          return "redirect:/queryBeOrderuser";
	}

}
